package com.kk.util.test.thread.example;

/**
 * @function:
 * @author: kevin
 * @date: 2018-09-07 18:14
 */
public class ConsumerThread extends Thread {

    private ObjectData data;

    public ConsumerThread(ObjectData data) {
        this.data = data;
    }

    public void run() {
        while (true) {
            synchronized (data) {
                try {
                    if (data.read() && data.getCount()>10) {
                        data.consumer();
                    } else {
                        Thread.sleep(100);
                    }

                    data.notify();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }


            }
        }
    }
}
